CREATE TABLE [dbo].[tb_ModalidadesEnsenanza]
(
[idModalidad] [int] NOT NULL IDENTITY(1, 1),
[Descripcion] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Mnemo] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[updatetb_ModalidadesEnsenanza] ON [dbo].[tb_ModalidadesEnsenanza]
 FOR UPDATE AS 
SET NOCOUNT ON
 IF (update(idModalidad)) begin 
	 SELECT * FROM inserted 
	 IF @@ROWCOUNT = 1 begin 
		 UPDATE tb_Concursos
		 SET Modalidad = (SELECT idModalidad FROM inserted)
		 WHERE tb_Concursos.Modalidad = (SELECT idModalidad FROM deleted)
		 UPDATE tb_SubOrganizaciones
		 SET Modalidad = (SELECT idModalidad FROM inserted)
		 WHERE tb_SubOrganizaciones.Modalidad = (SELECT idModalidad FROM deleted)
	end  ELSE begin 
		 ROLLBACK TRANSACTION 
 end 
 end
GO
ALTER TABLE [dbo].[tb_ModalidadesEnsenanza] ADD CONSTRAINT [PK_tb_ModalidadesEnsenanza] PRIMARY KEY CLUSTERED  ([idModalidad]) ON [PRIMARY]
GO
